package com.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import com.administration.entity.resultsetmapping.PrivilegeMapping;

/*
 * @author Karim Sherif
 */
@ManagedBean(name = "registeredUser")
@SessionScoped
public class RegisteredUser implements Serializable {
	private static final long serialVersionUID = -9065465228061817197L;

	private Long groupId;
	private Long userId;
	List<PrivilegeMapping> privilegeMappingList = new ArrayList<PrivilegeMapping>();
	List<Long> categoryList = new ArrayList<Long>();
	private String direction = "rtl";
	private String locale = "ar";

	// ##############################################################################
	public RegisteredUser() {
	}

	public boolean hasPrivilege(int privilegeId) {
		for (PrivilegeMapping pm : privilegeMappingList) {
			if (privilegeId == pm.getPrivilegeId()) {
				return true;
			}
		}
		return false;
	}

	public boolean hasCategoryPrivilege(Long categoryId) {
		boolean h = false;
		for (Long l : categoryList) {
			if (l.equals(categoryId)) {
				h = true;
				break;
			}
		}
		return h;
	}

	public String changeToRTL() {
		this.direction = "rtl";
		return null;
	}

	public String changeToLTR() {
		this.direction = "ltr";
		return null;
	}

	// ##############################################################################

	@Override
	public String toString() {
		return "RegisteredUser [groupId=" + groupId + ", userId=" + userId
				+ ", privilegeMappingList=" + privilegeMappingList
				+ ", categoryList=" + categoryList + ", direction=" + direction
				+ ", locale=" + locale + "]";
	}

	public long getGroupId() {
		return groupId;
	}

	public void setGroupId(Long groupId) {
		this.groupId = groupId;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public List<PrivilegeMapping> getPrivilegeMappingList() {
		return privilegeMappingList;
	}

	public void setPrivilegeMappingList(
			List<PrivilegeMapping> privilegeMappingList) {
		this.privilegeMappingList = privilegeMappingList;
	}

	public List<Long> getCategoryList() {
		return categoryList;
	}

	public void setCategoryList(List<Long> categoryList) {
		this.categoryList = categoryList;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public String getDirection() {
		return direction;
	}

	public void setLocale(String locale) {
		this.locale = locale;
	}

	public String getLocale() {
		return locale;
	}

}
